package com.atguigu.gulimall.order.controller;

import com.atguigu.common.utils.R;
import com.atguigu.gulimall.order.entity.OrderReturnReasonEntity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.UUID;

@Slf4j
@RestController
@RabbitListener(queues = "hello-queue")
public class RabbitMQController {
    @Autowired
    private RabbitTemplate rabbitTemplate;

    @GetMapping("/send")
    public R send() {
        OrderReturnReasonEntity entity = new OrderReturnReasonEntity();
        entity.setId(1L);
        entity.setName("啥啥");
        entity.setSort(1);
        entity.setCreateTime(new Date());
        rabbitTemplate.convertAndSend("hello-exchange", "hello-java", entity, new CorrelationData(UUID.randomUUID().toString()));
        log.info("Message sent");
        return R.ok();
    }
}
